package com.chance.cc.crawler.development.bootstrap.kuaihe;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpConstant;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.HttpRequestBody;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

import static com.chance.cc.crawler.core.downloader.HttpRequestBody.ContentType.FORM;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2021/1/24 10:06
 * @Description
 *      1919
 **/
public class KuaiHe {

    public static void main(String[] args) {
        String domain = "kuaihe";
        String entranceUrl = "https://kuaihe-720.1919.cn/sys/init.do";

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()//控制台输出
//                .fileResultPipeline("D:\\chance\\log\\tets.log",true) //文件输出
                .requestRecord(createCrawlerRequestRecord(domain,entranceUrl))
                .build()
                .start();
    }

    public static CrawlerRequestRecord createCrawlerRequestRecord(String domain,String url){
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(String.join("-","filter",domain,"queue")))
                .releaseTime(System.currentTimeMillis())
                .build();
        HttpRequest httpRequest = crawlerRequestRecord.getHttpRequest();
        httpRequest.setMethod(HttpConstant.Method.POST);
        httpRequest.setRequestBody(HttpRequestBody.custom("data=".getBytes(),FORM,"UTF-8"));

        return crawlerRequestRecord;
    }
}
